package com.example;

import java.util.Properties;

/**
 * @author : H-Thien
 * @comment :
 */
public class Config {

	private static Config instance = new Config();
	private Properties properties = new Properties();

	/**
	 * @comment :
	 */
	public static Config getInstance() {
		return instance;
	}

	/**
	 * @comment :
	 */
	public int getInt(String key, int defaultValue) {
		try {
			return Integer.parseInt(this.properties.getProperty(key));
		} catch (Exception e) {
			return defaultValue;
		}
	}

	/**
	 * @comment :
	 */
	public String getString(String key) {
		if (this.properties.getProperty(key) != null) {
			return this.properties.getProperty(key);
		} else {
			return "";
		}
	}

	/**
	 * @comment :
	 */
	public String getString(String key, String defaultValue) {
		if (this.properties.getProperty(key) != null) {
			return this.properties.getProperty(key);
		} else {
			return defaultValue;
		}
	}

	/**
	 * @comment :
	 */
	public boolean getBoolean(String s) {
		String d = this.properties.getProperty(s);
		try {
			return d.equals("true") || d.equals("on");
		} catch (Exception e) {
			return false;
		}
	}

	/**
	 * @comment :
	 */
	public void setProperties(Properties properties) {
		this.properties = properties;
	}
}